<?php

namespace App\Repositories\Config;


use App\Models\Config\Games;
use App\Repositories\BaseRepository;

class GamesRepository extends BaseRepository
{
    public function __construct(Games $model)
    {
        $this->model = $model;
    }

    //获取分页后的    所有游戏
    public function getPageGames($request)
    {
        $pageSize = 10;
        if (!empty($request->get('page_size'))) {
            $pageSize = $request->get('page_size');
        }

        return Games::query()->latest('id')->paginate($pageSize);
    }

    /**
     * 获取全部的游戏信息
     */
    public function getWithGame($condition)
    {
        $query = Games::query();
        if (isset($condition['status'])) {
            $query->where('status', '=', $condition['status']);
        }
        return $query->orderBy('id', 'DESC')->get()->toArray();
    }

    /**
     * 获取有权查看的 所有游戏
     */
    public function getGameWithAuth($gamesAuth)
    {
        return Games::query()->whereIn('game_id', $gamesAuth)->orderBy('id', 'DESC')->get()->toArray();
    }

    public function ById($id)
    {
        return Games::find($id);
    }
}